package o;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import com.huawei.appmarket.service.appmgr.view.activity.AppManagerProtocol;
import java.util.LinkedList;
import java.util.List;
import o.ewm.e;
import o.ewm.n;

public class dwt {
    private static dwt ˊ = null;
    private List<d> ˋ = new LinkedList();
    private androidx.core.app.NotificationCompat.d ˎ;
    private int ˏ;
    private long ॱ;

    static class d {
        private String ˎ;
        private long ˏ;

        d(long j, String str) {
            this.ˏ = j;
            this.ˎ = str;
        }
    }

    public static dwt ॱ() {
        if (ˊ == null) {
            ˊ = new dwt();
        }
        return ˊ;
    }

    private dwt() {
        Context ˋ = ContentManager.getInstant().getContext();
        this.ˎ = new androidx.core.app.NotificationCompat.d(ˋ);
        this.ˎ.ˏ(false);
        this.ˎ.ˊ(true);
        this.ˎ.ˎ(null);
        this.ˎ.ॱ(true);
        this.ˎ.ˏ(-1);
        this.ˎ.ˊ(e.ॱ);
        this.ˎ.ˏ(null);
        AppManagerProtocol appManagerProtocol = new AppManagerProtocol();
        appManagerProtocol.ˊ().ॱ(false);
        Intent ॱ = appManagerProtocol.ˎ().ॱ(ˋ);
        ॱ.addFlags(536870912);
        this.ˎ.ˎ(PendingIntent.getActivity(ˋ, 20191205, ॱ, 268435456));
    }

    public void ॱ(long j, String str) {
        for (d ˋ : this.ˋ) {
            if (ˋ.ˏ == j) {
                Logger.ˎ("DownloadNotification", "app is added to queue");
                return;
            }
        }
        this.ˋ.add(new d(j, str));
        Logger.ˎ("DownloadNotification", "add to queue " + str);
    }

    boolean ˏ(long j) {
        int i = 0;
        while (i < this.ˋ.size()) {
            if (((d) this.ˋ.get(i)).ˏ == j) {
                break;
            }
            i++;
        }
        i = -1;
        if (i == -1) {
            return false;
        }
        this.ˋ.remove(i);
        return true;
    }

    d ˏ() {
        if (this.ˋ == null || this.ˋ.isEmpty()) {
            return null;
        }
        return (d) this.ˋ.get(0);
    }

    public void ˏ(long j, String str, int i, long j2) {
        ˏ(j);
        this.ॱ = j;
        this.ˏ = 1;
        String ˋ = dwa.ˋ(j2);
        Context ˋ2 = ContentManager.getInstant().getContext();
        CharSequence string = ˋ2.getString(n.ʾˊ, new Object[]{ˋ, str});
        this.ˎ.ˊ(System.currentTimeMillis());
        this.ˎ.ˏ(string);
        this.ˎ.ˊ(100, i, false);
        ˊ(ˋ2);
    }

    public void ˊ() {
        if (this.ˏ == 1) {
            Logger.ˎ("DownloadNotification", "should not show notification when downloading notification is showing");
            return;
        }
        Context ˋ = ContentManager.getInstant().getContext();
        d ˏ = ˏ();
        if (ˏ == null) {
            Logger.ˎ("DownloadNotification", "can not get wait download data");
            return;
        }
        this.ॱ = ˏ.ˏ;
        this.ˏ = 0;
        CharSequence string = ˋ.getString(n.ʽʽ, new Object[]{ˏ.ˎ});
        this.ˎ.ˊ(System.currentTimeMillis());
        this.ˎ.ˏ(string);
        this.ˎ.ˊ(100, 0, false);
        ˊ(ˋ);
    }

    private void ˊ(Context context) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        if (notificationManager != null) {
            if (VERSION.SDK_INT >= 26) {
                NotificationChannel notificationChannel = new NotificationChannel("download.notification.channel", context.getString(n.ʻـ), 3);
                notificationChannel.enableVibration(false);
                notificationChannel.setSound(null, null);
                if (notificationManager.getNotificationChannel(notificationChannel.getId()) == null) {
                    notificationManager.createNotificationChannel(notificationChannel);
                }
                this.ˎ.ˋ(notificationChannel.getId());
            }
            notificationManager.notify("Appgallery_DownloadNotification", 20191205, this.ˎ.ˊ());
        }
    }

    public void ˋ(long j) {
        Logger.ˎ("DownloadNotification", "remove: " + j + " from queue, result: " + ˏ(j));
        if (this.ॱ == j) {
            cei.ˋ(ContentManager.getInstant().getContext(), "DownloadNotification", 20191205);
            this.ॱ = -1;
            this.ˏ = -1;
        }
        ˊ();
    }
}
